package com.ztsjglxt.core.impl;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.Calendar;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.Transactional;

import com.ztsjglxt.core.Ibasecommon;
import com.ztsjglxt.dao.DynamicSQL;




@Service
@EnableTransactionManagement
@Transactional
public class basecommonimpl implements Ibasecommon {
	private static final long serialVersionUID = 2644136098883761056L;

	@Autowired
	DynamicSQL dsql;

	/**
	 * 根据查询条件读取list
	 * @author bxf
	 */
	@Override
	public List<Map> getlistfromtable(String tablename, String Strwhere,
			String OrderField) {
		StringBuilder MyStringBuilder = new StringBuilder("select * from "
				+ tablename);
		if (!StringUtils.isBlank(Strwhere)) {
			MyStringBuilder.append("  where " + Strwhere);
		}
		if (!StringUtils.isBlank(OrderField)) {
			MyStringBuilder.append("  order by  " + OrderField);
		}
		return dsql.dynamic_sql2(MyStringBuilder.toString());
	}

	/**
	 * 读取数据
	 * @author bxf
	 */
	@Override
	public List<Map> getlistfromid(String tablename, String fieldgets,
			String Strwhere) {
		StringBuilder MyStringBuilder = new StringBuilder("select " + fieldgets
				+ " from " + tablename);
		if (!StringUtils.isBlank(Strwhere)) {
			MyStringBuilder.append("  where " + Strwhere);
		}
		return dsql.dynamic_sql2(MyStringBuilder.toString());
	}

	/**
	 * 读取数据
	 * @author bxf
	 */
	@Override
	public List<Map> getlistfromsql(String sql) {
		if (StringUtils.isBlank(sql)) {
			return null;
		}
		return dsql.dynamic_sql2(sql.toString());
	}


}
